package com.kun.service_order.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kun.service_order.client.EduClient;
import com.kun.service_order.client.MemberClient;
import com.kun.service_order.entity.TOrder;
import com.kun.service_order.mapper.TOrderMapper;
import com.kun.service_order.service.TOrderService;
import com.kun.service_order.utils.OrderNoUtil;
import com.kun.vo.CourseOrderVo;
import com.kun.vo.UcenterMemberOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author dmk
 * @since 2021-10-31
 */
@Service
public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> implements TOrderService {
    @Autowired
    private EduClient eduClient;
    @Autowired
    private MemberClient memberClient;
    @Override
    public String createOrders(String courseId, String memberId) {
        UcenterMemberOrder memberOrder = memberClient.getMemberOrder(memberId);
        CourseOrderVo courseInfoOrder = eduClient.getCourseInfoOrder(courseId);
        TOrder tOrder = new TOrder();
        tOrder.setOrderNo(OrderNoUtil.getOrderNo());
        tOrder.setCourseId(courseInfoOrder.getId());
        tOrder.setCourseCover(courseInfoOrder.getCover());
        tOrder.setTeacherName(courseInfoOrder.getTeacherName());
        tOrder.setTotalFee(courseInfoOrder.getPrice());
        tOrder.setMemberId(memberId);
        tOrder.setMobile(memberOrder.getMobile());
        tOrder.setNickname(memberOrder.getNickname());
        tOrder.setStatus(0);
        tOrder.setPayType(1);
        baseMapper.insert(tOrder);
        return tOrder.getOrderNo();
    }
}
